﻿
@{
    ViewBag.Title = "修改密码";
    Layout = "~/Views/Shared/_UserLayout.cshtml";
}

<!--修改密码样式-->
<div class="user_style clearfix" id="user">
    <div class="user_title"><em></em>用户中心</div>
    <div class="clearfix user">
        <!--左侧菜单栏样式-->
        @Html.Partial("~/Views/Shared/_PartialUserLeft.cshtml")
        <!--右侧样式-->
        <div class="right_style r_user_style user_right">
            <div class="user_Borders">
                <div class="title_name">
                    <span class="name">修改密码</span>
                </div>
                <!--修改密码样式-->
                <div class="about_user_info">
                    <form id="form1" class="layui-form" method="post">
                        <div class="user_layout">
                            <ul>
                                <li><label class="user_title_name">原密码：</label><input   lay-verify="required|pass" name="Password" type="password" class="add_text" /><i>*</i></li>
                                <li><label class="user_title_name">新密码：</label><input id="pwd" name="NewPassword" lay-verify="required|pass" type="password" class="add_text" /><i>*</i></li>
                                <li><label class="user_title_name">确认新密码：</label><input  name="ReNewPassword" lay-verify="required|repass"  type="password" class="add_text" /><i>*</i></li>
                            </ul>
                            <div class="operating_btn"><input lay-filter="edit" lay-submit="" type="button" value="确认" class="submit—btn" /></div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>

@section FooterScript{
    <script src="~/common/Threelinkage/layui/layui.all.js"></script>
    <script type="text/javascript">

        layui.config({
            base: "js/"
        }).use(['form', 'layer', 'jquery', 'layedit'], function () {
            var form = layui.form,
                layer = parent.layer === undefined ? layui.layer : parent.layer,
                laypage = layui.laypage,
                layedit = layui.layedit,
                $ = layui.jquery;

            //数据验证
            form.verify({
                pass: [/^[a-zA-Z0-9].{5,17}$/, '密码以字母开头长度为6~18，只能包含字母、数字和字符'],
                repass: function (value) {
                    if ($('#pwd').val() != value) {
                        return '两次输入的密码不一致';
                    }
                }
            });


            //此处的addNew是38行代码中提交按钮的 lay-filter属性
            form.on("submit(edit)", function (data) {

                var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });

                var formData = $(".layui-form").serialize();    //表单数据

                $.ajax({
                    url: "/User/UpdatePassword",
                    type:"POST",
                    dataType: "json",
                    data: formData,
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.msg("修改成功", {
                                icon: 1, time: 2000, end: function () {
                                    top.layer.close(index);

                                    //刷新父页面
                                    location.reload();
                                }
                            });



                        } else {
                            layer.msg("修改失败:" + res.errorMsg, {
                                icon: 5, time: 2000, end: function () {
                                    top.layer.close(index);
                                }
                            });
                        }
                    },
                    error: function () {
                        layer.msg("网络请求失败", {
                            icon: 5, time: 2000, end: function () {
                                top.layer.close(index);
                                layer.closeAll("iframe");
                                //刷新父页面
                                //location.reload();
                            }
                        });
                    }
                });

                return false;
            })

        })

    </script>
}